<!-- SKU详情 - 综合表单页面 -->
<template>
  <div class="page-container">
    <ex_super_form ref="form" v-bind="option" v-loading="loading"
      class="common-form-row common-form-panel-div-right flex_auto" label-position="right" label-width="140px"
      style="overflow-y: auto;">
    </ex_super_form>
    <div style="margin-left: 140px;" class="mg_t2">
      <el-button type="primary" @click="submitForm()">{{ $tt('label_confirm') }}</el-button>
      <el-button @click="return_page_back">{{ $tt('label_cancel') }}</el-button>
    </div>
  </div>
</template>
<script>


import router_params from '@/mixin/router_params';
export default {
  mixins: [router_params],
  components: {},

  data() {
    return {
      edit: false,
      loading: false,
      option: {
        itemClass: "form_item_mini", inputClass: "form_input_small",

        default: {
          status: "ENABLE",
          sizeUnit: "M",
          weightUnit: "KG",
          countryCode: "CN",
          countryName: "中国"
        },
        model: [
          { header: "label_base_info", },
          {
            grid: [
              [
                { col: { key: 'code', label: 'label_warehouse_code', disabled: (data) => !_.isEmpty(data.id) }, },
                { col: { key: 'name', label: 'label_warehouse_name', disabled: (data) => !_.isEmpty(data.id) }, },
              ],
              [
                {
                  col: {
                    key: 'serverCode',
                    label: 'label_machine_room_address',
                    type: 'select',
                    url: '/oms-api/base/BaseMachineRoomRpc/selectAll.json',
                    option: { label: 'name', value: 'code' }
                  },
                },
                { col: { key: 'type', label: 'label_warehouse_type', type: 'select', enum: 'WarehouseTypeEnum', }, },
              ],
              [
                {
                  col: { key: 'manageType', label: 'label_operation_type', type: 'select', enum: 'WarehouseManageTypeEnum', },
                },
                { col: { key: 'position', label: 'label_warehouse_place', type: 'select', enum: 'BaseWarehousePositionEnum', }, },
              ],
              [
                {
                  col: {
                    key: 'countryName',
                    label: 'label_country',
                    filterable: true,
                    type: 'select',
                    url: '/tms-api/base/TmsPlaceInfoRpc/selectCountry.json',
                    storeData: true,
                    option: { label: 'labelStr', value: 'countryName' },
                    keyExtra: { countryName: 'countryName', countryCode: 'countryCode' }
                  },
                },
                { col: { key: 'province', label: 'label_province', }, },
              ],
              [
                { col: { key: 'city', label: 'label_city', }, },
                {
                  col: { key: 'county', label: 'label_region', },
                },
               
              ],
              [
                { col: { key: 'postcode', label: 'label_zip_code', }, },
                { col: { key: 'address', label: 'label_detail_address', }, },
              
              ],
              [

                {
                  col: { key: 'contacter', label: 'label_contact', },
                },
                { col: { key: 'phone', label: 'label_contact_phone', }, },
              ],
              [
                {
                  col: { key: 'totalArea', label: 'label_whole_warehouse_proportion', append: 'm³', appendClass: 'input_slot_div_mini' },
                },
                { col: { key: 'usableArea', label: 'label_usable_warehouse_proportion', append: 'm³', appendClass: 'input_slot_div_mini' }, },
              ],
              [
                {
                  col: { key: 'longitude', label: 'label_lon', },
                },
                { col: { key: 'latitude', label: 'label_lat', }, },
              ],
              [
                {
                  col: {
                    key: 'timeZone',
                    label: 'label_warehouse_timeZone',
                    type: 'select',
                    enum: 'TimeZoneEnum'
                  }
                },
              ],
            ]
          },
        ],
        rules: {
          'code': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' }],
          'name': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' }],
          'type': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' }],
          'manageType': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' }],
          'position': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' }],
          'countryName': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' }],
          'state': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' }],
          'province': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' }],

          'city': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' }],
          'county': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' }],
          'address': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' }],
          'contacter': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' }],
          'phone': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' }],
          'postcode': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' }],
          'timeZone': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' }],
          'serverCode': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' }],
        },
      },


    };
  },

  methods: {


    init_data_default(into_params) {
      this.edit = !!into_params.edit
      if (this.edit) {
        if (into_params.id) {
          this.loading = true
          this.$ajax({
            url: "/oms-api/base/OmsBaseWarehouseRpc/detail.json",
            method: 'post',
            data: { id: into_params.id },
            success: (res) => {
              if (!res.data) return this.$message.error(this.$tt("label_data_loss"))
              this.$nextTick(() => {
                this.$refs.form.setData(res.data)
                this.$refs.form.clearValidate()
              })
              this.fixTabLabel(res.data.name)
            },
            complete: () => {
              this.loading = false
            }
          })
        }
      }
      this.fixTabLabel()
    },
    fixTabLabel(name) {
      if (this.edit) {
        this.$emit("tagModifyLabel", { _key: 'label_name_code', name: this.$tt('label_edit_warehouse'), code: name || '' })
      } else {
        this.$emit("tagModifyLabel", "label_new_warehouse")
      }
    },

    submitForm() {
      this.$refs['form'].validate((valid, obj) => {
        if (valid) {
          this.$ajax({
            url: "/oms-api/base/OmsBaseWarehouseRpc/insertOrUpdate.json",
            method: 'post',
            type: 'json',
            loading: this.$tt('tip_submiting'),
            data: this.$refs.form.getFormData(),
            success: (res) => {
              this.$message.success(this.$tt('tip_submit_success'))
              this.return_emit(null, "reload")
              this.return_page_back()
              this.$store.dispatch('setAllWarehouseAction')
            }
          })
        } else {
          this.$message.error(this.$tt('form_validate_error'))
          return false;
        }
      });

    },
  }
};

</script>
<style></style>
